﻿using System;
using System.Web;
using Ext.Net;
using System.Collections.Generic;
using System.Collections;
using Film.Repository;

namespace PhuongDoAn.Admin.Occupation.handler
{
    /// <summary>
    /// Summary description for ListHandler
    /// </summary>
    public class ListHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string query = "";
            int start = 0;
            int limit = 25;
            int count = 0;

            if (!string.IsNullOrEmpty(context.Request["query"]))
            {
                query = context.Request["query"];
            }
            if (!string.IsNullOrEmpty(context.Request["start"]))
            {
                int.TryParse(context.Request["start"], out start);
            }

            if (!string.IsNullOrEmpty(context.Request["limit"]))
            {
                int.TryParse(context.Request["limit"], out limit);
            }
            List<tblOccupation> result = new List<tblOccupation>();
            tblOccupationRepository countryRepository = new tblOccupationRepository();
            result = countryRepository.Filter(query, start, limit, out count);
            List<tblOccupationHandler> listHandler = result.ConvertAll<tblOccupationHandler>(delegate(tblOccupation e)
            {
                return new tblOccupationHandler() { OccupationID = e.OccupationID, OccupationName = e.OccupationName };
            });
            context.Response.Write(string.Format("{{'Data':{0},'TotalRecords':{1}}}", JSON.Serialize(listHandler), count));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    public class tblOccupationHandler
    {
        public int OccupationID { get; set; }
        public string OccupationName { get; set; }
    }
}